<!DOCTYPE html>
<html>
<head>
    <title>历史</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <#--样式-->
    <link rel="stylesheet" media="screen" href="${request.contextPath}/css/style.css">
    <#--layui-->
    <link rel="stylesheet" media="screen" href="${request.contextPath}/layui/css/layui.css">

</head>
<body >





    <div class="content" >



       <div >
           <#--月亮放置区-->
           <div class="light" style="cursor:pointer;" onclick="window.location.href = '/history/'">
           </div>

           <hr class="line-left">
           <hr class="line-right">

           <div class="main">
               <h1 class="title">更新事件</h1>
           </div>




           <div class="textContent" style="padding-bottom: 300px;">

               <div style="width: 900px;">

                   <#if imgList??>
                   <#--轮播图-->
                       <div class="layui-carousel" id="loopImg">
                           <div carousel-item="" style="text-align:center;">
                               <#list imgList as img>
                                   <div>
                                       <img style="max-width:300px;max-height:400px;" src="/history/other/read?id=${img.path}" />
                                   </div>
                               </#list>
                               <#--<img style="max-width:300px;" src="/history/img/light-top.png">-->
                           </div>
                       </div>
                       <br/>
                   </#if>

                   <form class="layui-form" id="formEventOccur">
                        <input type="hidden" name="id" value="${eventOccur.id!''}"/>

                       <div class="layui-form-item">
                           <label class="layui-form-label">历史主线</label>
                           <div class="layui-input-block">
                               <select name="historyId" lay-filter="aihao" lay-search>
                                   <option value="">请选择历史主线</option>
                                   <#if historyMainList??>
                                       <#list historyMainList as historyMain>
                                           <#if historyMain??>
                                                <#if historyMain.ad == 1>
                                                    <#if historyMain.accuracy == 1>
                                                        <option value="${historyMain.id!''}" <#if eventOccur.historyId == historyMain.id>selected="selected"</#if> >约 公元元年</option>
                                                    <#else >
                                                        <option value="${historyMain.id!''}" <#if eventOccur.historyId == historyMain.id>selected="selected"</#if> >公元元年</option>
                                                    </#if>

                                                <#elseif historyMain.ad < 0>
                                                    <#if historyMain.accuracy == 1>
                                                        <option value="${historyMain.id!''}" <#if eventOccur.historyId == historyMain.id>selected="selected"</#if> >约 公元前 ${historyMain.ad!''} 年</option>
                                                    <#else >
                                                        <option value="${historyMain.id!''}" <#if eventOccur.historyId == historyMain.id>selected="selected"</#if> >公元前 ${historyMain.ad!''} 年</option>
                                                    </#if>

                                                <#else >
                                                    <#if historyMain.accuracy == 1>
                                                        <option value="${historyMain.id!''}" <#if eventOccur.historyId == historyMain.id>selected="selected"</#if> >约 公元 ${historyMain.ad!''} 年</option>
                                                    <#else >
                                                        <option value="${historyMain.id!''}" <#if eventOccur.historyId == historyMain.id>selected="selected"</#if> >公元 ${historyMain.ad!''} 年</option>
                                                    </#if>

                                                </#if>
                                           </#if>
                                       </#list>
                                   </#if>
                               </select>
                           </div>
                       </div>
                       <hr class="layui-bg-orange">


                       <fieldset class="layui-elem-field layui-field-title">
                           <legend>框定时间</legend>
                       </fieldset>


                       <div class="layui-form-item">
                           <label class="layui-form-label">月份</label>
                           <div class="layui-input-block">
                               <select name="month" lay-filter="aihao">
                                   <option  value="">事件发生的月份</option>
                                   <option <#if eventOccur.month == 1>selected="selected"</#if> value="1">一 月</option>
                                   <option <#if eventOccur.month == 2>selected="selected"</#if> value="2">二 月</option>
                                   <option <#if eventOccur.month == 3>selected="selected"</#if> value="3">三 月</option>
                                   <option <#if eventOccur.month == 4>selected="selected"</#if> value="4">四 月</option>
                                   <option <#if eventOccur.month == 5>selected="selected"</#if> value="5">五 月</option>
                                   <option <#if eventOccur.month == 6>selected="selected"</#if> value="6">六 月</option>
                                   <option <#if eventOccur.month == 7>selected="selected"</#if> value="7">七 月</option>
                                   <option <#if eventOccur.month == 8>selected="selected"</#if> value="8">八 月</option>
                                   <option <#if eventOccur.month == 9>selected="selected"</#if> value="9">九 月</option>
                                   <option <#if eventOccur.month == 10>selected="selected"</#if> value="10">十 月</option>
                                   <option <#if eventOccur.month == 11>selected="selected"</#if> value="11">十一 月</option>
                                   <option <#if eventOccur.month == 12>selected="selected"</#if> value="12">十二 月</option>
                               </select>
                           </div>
                       </div>
                       <div class="layui-form-item">
                           <label class="layui-form-label">天|日期</label>
                           <div class="layui-input-block">
                               <select name="dateOccur" lay-filter="aihao">
                                   <option value="">事件发生在哪一天</option>
                                   <option <#if eventOccur.dateOccur == 1>selected="selected"</#if> value="1">一 号</option>
                                   <option <#if eventOccur.dateOccur == 2>selected="selected"</#if> value="2">二 号</option>
                                   <option <#if eventOccur.dateOccur == 3>selected="selected"</#if> value="3">三 号</option>
                                   <option <#if eventOccur.dateOccur == 4>selected="selected"</#if> value="4">四 号</option>
                                   <option <#if eventOccur.dateOccur == 5>selected="selected"</#if> value="5">五 号</option>
                                   <option <#if eventOccur.dateOccur == 6>selected="selected"</#if> value="6">六 号</option>
                                   <option <#if eventOccur.dateOccur == 7>selected="selected"</#if> value="7">七 号</option>
                                   <option <#if eventOccur.dateOccur == 8>selected="selected"</#if> value="8">八 号</option>
                                   <option <#if eventOccur.dateOccur == 9>selected="selected"</#if> value="9">九 号</option>
                                   <option <#if eventOccur.dateOccur == 10>selected="selected"</#if> value="10">十 号</option>
                                   <option <#if eventOccur.dateOccur == 11>selected="selected"</#if> value="11">十一 号</option>
                                   <option <#if eventOccur.dateOccur == 12>selected="selected"</#if> value="12">十二 号</option>
                                   <option <#if eventOccur.dateOccur == 13>selected="selected"</#if> value="13">十三 号</option>
                                   <option <#if eventOccur.dateOccur == 14>selected="selected"</#if> value="14">十四 号</option>
                                   <option <#if eventOccur.dateOccur == 15>selected="selected"</#if> value="15">十五 号</option>
                                   <option <#if eventOccur.dateOccur == 16>selected="selected"</#if> value="16">十六 号</option>
                                   <option <#if eventOccur.dateOccur == 17>selected="selected"</#if> value="17">十七 号</option>
                                   <option <#if eventOccur.dateOccur == 18>selected="selected"</#if> value="18">十八 号</option>
                                   <option <#if eventOccur.dateOccur == 19>selected="selected"</#if> value="19">十九 号</option>
                                   <option <#if eventOccur.dateOccur == 20>selected="selected"</#if> value="20">二十 号</option>
                                   <option <#if eventOccur.dateOccur == 21>selected="selected"</#if> value="21">二十一 号</option>
                                   <option <#if eventOccur.dateOccur == 22>selected="selected"</#if> value="22">二十二 号</option>
                                   <option <#if eventOccur.dateOccur == 23>selected="selected"</#if> value="23">二十三 号</option>
                                   <option <#if eventOccur.dateOccur == 24>selected="selected"</#if> value="24">二十四 号</option>
                                   <option <#if eventOccur.dateOccur == 25>selected="selected"</#if> value="25">二十五 号</option>
                                   <option <#if eventOccur.dateOccur == 26>selected="selected"</#if> value="26">二十六 号</option>
                                   <option <#if eventOccur.dateOccur == 27>selected="selected"</#if> value="27">二十七 号</option>
                                   <option <#if eventOccur.dateOccur == 28>selected="selected"</#if> value="28">二十八 号</option>
                                   <option <#if eventOccur.dateOccur == 29>selected="selected"</#if> value="29">二十九 号</option>
                                   <option <#if eventOccur.dateOccur == 30>selected="selected"</#if> value="30">三十 号</option>
                                   <option <#if eventOccur.dateOccur == 31>selected="selected"</#if> value="31">三十一 号</option>
                               </select>
                           </div>
                       </div>
                       <div class="layui-form-item">
                           <label class="layui-form-label">季节</label>
                           <div class="layui-input-block">
                               <select name="seasons" lay-filter="aihao">
                                   <option value="">请选择季节</option>
                                   <option <#if eventOccur.seasons == 1>selected="selected"</#if> value="1">春</option>
                                   <option <#if eventOccur.seasons == 2>selected="selected"</#if> value="2">夏</option>
                                   <option <#if eventOccur.seasons == 3>selected="selected"</#if> value="3">秋</option>
                                   <option <#if eventOccur.seasons == 4>selected="selected"</#if> value="4">冬</option>
                               </select>
                           </div>
                       </div>
                       <hr class="layui-bg-orange">


                       <fieldset class="layui-elem-field layui-field-title">
                           <legend>添加事件</legend>
                       </fieldset>
                       <div class="layui-form-item layui-form-text">
                           <label class="layui-form-label">事件</label>
                           <div class="layui-input-block">
                               <textarea placeholder="请输入发生的事件，必填" lay-verify="required" required name="content" class="layui-textarea">${eventOccur.content!''}</textarea>
                           </div>
                       </div>
                       <hr class="layui-bg-orange">





                       <fieldset class="layui-elem-field layui-field-title">
                           <legend>附加信息</legend>
                       </fieldset>


                       <div class="layui-form-item">
                           <label class="layui-form-label">地点</label>
                           <div class="layui-input-block">
                               <input type="text" name="place" value="${eventOccur.place!''}"  lay-verify="title" autocomplete="off" placeholder="事件发生地点" class="layui-input">
                           </div>
                       </div>
                       <div class="layui-form-item">
                           <label class="layui-form-label">中国史|外国史</label>
                           <div class="layui-input-block">
                               <input type="radio" <#if eventOccur.abroadOrHome == "1">checked</#if> name="abroadOrHome" value="1" title="国内" >
                               <input type="radio" <#if eventOccur.abroadOrHome == "2">checked</#if> name="abroadOrHome" value="2" title="国外">
                           </div>
                       </div>
                       <div class="layui-form-item">
                           <label class="layui-form-label">是否重大事件</label>
                           <div class="layui-input-block">
                               <input type="radio" <#if eventOccur.important == "1">checked</#if> name="important" value="1" title="普通事件">
                               <input type="radio" <#if eventOccur.important == "2">checked</#if> name="important" value="2" title="重大事件">
                           </div>
                       </div>


                       <br/>
                       <br/>


                       <div class="layui-form-item">
                           <div class="layui-input-block">
                               <button class="layui-btn" lay-submit lay-filter="updEventOccur">更新</button>
                               <button class="layui-btn layui-btn-danger" type="button" onclick="delEvent()" >删除</button>
                               <button class="layui-btn layui-btn-normal" type="button" onclick="toAddImg()" >前往图片</button>
                           </div>
                       </div>

                   </form>

               </div>




           </div>



       </div>
    </div>




</body>


<!-- scripts -->

<#--layui-->
<script src="${request.contextPath}/layui/layui.js"></script>
<#--js-->
<script src="${request.contextPath}/js/jquery.min.js"></script>


<script>


    /**
     *  前往上传图片
     */
    function toAddImg(){
        var id = $("input[name='id']").val();
        if (id == null || id === ""){
            layer.msg("数据异常，刷新后重试");
            return;
        }
        window.location.href = "/history/other/toAddImg?id=" + id;
    }

    /**
     * 轮播图
     */
    layui.use('carousel', function(){
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#loopImg'
            ,width: '300px' //设置容器宽度
            ,arrow: 'always' //始终显示箭头
            //,anim: 'updown' //切换动画方式
        });
    });



    // 引入弹出层
    var form = null;
    layui.use('form', function(){
        form = layui.form;

        /**
         * 监听提交,更新事件
         */
        form.on('submit(updEventOccur)', function(data){
            $.ajax({
                url:'/history/event/updEventOccur', //请求的url地址
                dataType:'json', //返回的格式
                data: $("#formEventOccur").serialize(),//参数值 {"id":"value"}
                type:'post', //请求的方式
                beforeSend:function(){ //请求前的处理
                    console.log("提交的数据:" + JSON.stringify(data.field))
                },
                success:function (req) {
                    if (req != null){
                        if (req.status === "success"){
                            layer.msg(req.msg);
                        } else {
                            layer.msg(req.msg);
                        }
                    } else {
                        console.log(req);
                    }
                },
                error:function (e) {
                    console.log(e);
                    layer.msg("未知错误");
                }
            });

            //返回false则不会重置
            return false;
        });
    });


    /**
     * 删除事件
     */
    function delEvent() {
        var id = $("input[name='id']").val();
        if (id === null || id === ""){
            layer.msg("数据异常，请刷新后重试");
            return;
        }

        layer.confirm('确认是否删除事件，注意：删除后不可恢复?', {icon: 3, title:'警告'}, function(index){
            $.ajax({
                url:'/history/event/delEventOccur', //请求的url地址
                dataType:'json', //返回的格式
                data: {"id" : id},//参数值 {"id":"value"}
                type:'get', //请求的方式
                beforeSend:function(){ //请求前的处理
                    console.log("提交的数据:" + id)
                },
                success:function (req) {
                    if (req != null){
                        if (req.status === "success"){
                            layer.msg(req.msg);

                        } else {
                            layer.msg(req.msg);
                        }
                    } else {
                        console.log(req);
                    }
                },
                error:function (e) {
                    console.log(e);
                    layer.msg("未知错误");
                }

            });

            layer.close(index);
        });
    }





</script>



</html>